package com.soft.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.soft.entity.Dept;
import com.soft.mapper.DeptMapper;

@Service
public class DeptService {
    @Autowired
    private DeptMapper deptMapper;
    
    public List<Dept> queryAll() {
        List<Dept> deptList = deptMapper.selectList(null);
        return deptList;
    }
    public List<Dept>queryByLoc(String locName)
    {
    	QueryWrapper<Dept> qw = new QueryWrapper<>();
    	qw.eq("dept_loc", locName);
    	List<Dept> deptList = deptMapper.selectList(qw);
    	return deptList;
    }
    public int insertOne(String deptName,String loc)
    {
    	Dept dept = new Dept();
    	dept.setDname(deptName);
    	dept.setLoc(loc);
    	int num = deptMapper.insert(dept);
    	return num;
    }
    public int deleteById(String id)
    {
    	Dept dept = new Dept();
    	dept.setDeptno(id);
    	int num = deptMapper.deleteById(dept);
    	return num;
    }
	public int deleteByName(String Dname)
	{
		QueryWrapper<Dept> qw = new QueryWrapper();
		qw.eq("dept_name", Dname);
		return deptMapper.delete(qw);
	}
	public int updateByDno(String dno)
	{
		UpdateWrapper<Dept> uw = new UpdateWrapper<>();
		uw.gt("deptno", dno);
		Dept dept = new Dept();
		dept.setLoc("秦皇岛");
		return deptMapper.update(dept,uw);
	}
}